<?php

defined( 'IN_CLASS' ) or die( 'Access Error!' );

class wordcontrol extends control {
	
	public function __construct() {
		$aC = $this->_chechlogin(); //检查用户登陆
		all::$aU = model::member()->get( $aC['id'] );
	}
	
	public function ondown() {
		all::$aOut['words'] = model::word()->downwords();
		func::display( all::$aOut, 'downword.htm' );
	}
	
	public function onindex() {
		all::$aOut['sms_num'] = model::sms()->checknew( all::$aU['id'] );
		all::$aOut['mod_name'] = all::$cfg['navname']['msg']; //模块名称
		all::$aOut['top10'] = model::member()->gettop10();//输出班级会员积分 TOP 10
		
		$page_curr = func::input( 'page', 'i' );  //申明当前页的变量，在分页函数中将给此变量赋值，方便处理后的重定向
		$page_size = all::$cfg['class']['words_per_page'];      //指定分页每一页多少条数据
		$limit = show_page( $page_size, 'limit' );  //设定当前页中的SQL的限制
		all::$aOut['msgs'] = model::word()->ls( $limit );
		all::$aOut['page_tip'] = show_page( $page_size );   //得到分页结果
		
		all::$aOut['page'] = $page_curr;   //输出当前页码，在删除、修改、发布处
		all::$aOut['msg_edit'] = 'none';   //在非编辑的情况下隐藏修改留言的链接
		
		$mid = func::input( 'mid', 'i' );
		if( $mid ) all::$aOut['aWord'] = model::word()->get( $mid ); //要编辑某条留言
		func::display( all::$aOut, 'leaveword.htm' );
	}
	
	public function onadd() {
		$page_curr = func::input( 'page', 'i' );
		$content = func::input( 'elm1', 's', '', false, true );
		if ( !empty( $content) ) {
			if ( model::word()->add( all::$aU['id'], $content ) ) {
				model::score()->member_score( all::$aU['id'], all::$cfg['suser']['lvword'] ); //留言的积分
			}
		}
		func::redirect( "./index.php" ); //添加成功，转向
	}
	
	public function ondel() {
		$mid = func::input ( 'mid', 'i' );  //信息对象ID
		$page_curr = func::input( 'page', 'i' );
		$aWord = model::word()->get( $mid );
		if ( all::$aU['id'] == $aWord['author'] || all::$aU['power'] > 1 ) { //自己或者管理员可以删除留言
			model::word()->del( $mid );  //删除
		}
		func::redirect( "./index.php?m=word&page={$page_curr}" ); //转向
	}
	
	public function onedit() {
		$mid = func::input ( 'mid', 'i' );  //信息对象ID
		$page_curr = func::input( 'page', 'i' );
		$content = func::input ( 'elm1', 's', false );
		$content && model::word()->edit( $mid, all::$aU['id'], $content ); //编辑
		func::redirect( "./index.php?m=word&page={$page_curr}" ); //转向
	}
	
	
}